var axiosModule = require("axios");

var myAxios = {
    axios:axiosModule,
    result:{},
    get:function(url, params){
        params = params||{}
        if(params){
            let h5Url = "";
            for(x in params){
                if(!h5Url){
                    h5Url += '?'+x+'='+params[x];
                }else{
                    h5Url += '&'+x+'='+params[x];
                }
            }
            url = url + h5Url;
        }
        let axios = this.axios;
        return new Promise((resolve,reject) => {
            axios.all([
                axios.get(url)
            ])
                .then(axios.spread((axRes)=>{resolve(axRes)}))
                .catch(error=>{reject(error)});
        });
    },
    post:function(url, params, config){
        let axios = this.axios;

        return new Promise((resolve,reject) => {
            axios.all([
                axios.post(url,params,config)
            ])
                .then(axios.spread((axRes)=>{resolve(axRes)}))
                .catch(error=>{console.error('【myAxios】 post err url='+url+' params='+JSON.stringify(params));reject(error)});
        });
    }
}

// async function test(){
//     let aa = await myAxios.post('http://www.baidu.com',{},{});
//     console.error('dddd');
//     console.log(aa);
// }
// test();
module.exports = myAxios;